import { createStore } from 'vuex'
import createPersistedState from "vuex-persistedstate";

export default createStore({
  plugins: [createPersistedState({
    paths: ['token', "userInfo"],
    // 默认使用的是localStorage,在开发阶段，可使用sessionStorage
    storage: window.sessionStorage
  })],
  state: {
    // 登录以后的用户信息
    userInfo: null,
    // 令牌
    token: null,
    actionSheetConfig: {
      isShow: false,
      list: [],
      successCallBack: null
    },
    addressInfo: null,
    currentAddress: null
  },
  mutations: {
    setAddressInfo(state, addressInfo) {
      state.addressInfo = addressInfo
    },
    setCurrentAddress(state, currentAddress) {
      state.currentAddress = currentAddress
    },
    showActionSheet(state, config) {
      state.actionSheetConfig.isShow = true
      state.actionSheetConfig.list = config.list
      state.actionSheetConfig.successCallBack = config.success
    },
    hideActionSheet(state) {
      state.actionSheetConfig.isShow = false
      state.actionSheetConfig.list = []
      state.actionSheetConfig.successCallBack = null
    },
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo
    },
    setToken(state, token) {
      state.token = token
    },
    logOut(state) {
      state.userInfo = null
      state.token = null
    }
  },
  actions: {
  },
  modules: {
  },
  getters: {
  }
})
